#include<iostream>
#include<unistd.h>
#include<sys/types.h>
#include<vector>

using namespace std;
void SubProcessRun()
{
    while(1)
    {
        cout<<"I am a sub process, pid: "<<getpid()<<"ppid: "<<getppid()<<std::endl;
        sleep(5);
    }
}
const int num =10;
int main()
{
    vector<pid_t> allchild;
    for(int i =0;i<num;i++)
    {
        pid_t id = fork();
        if(id == 0)
        {
          SubProcessRun();
        }
        allchild.push_back(id);
    }

    cout<<"我的所有孩子是:";
    for(auto child : allchild)
    {
        cout<<child<<" ";
    }
    cout<<endl;
    sleep(10);
    while(true)
    {
        cout<<"我是父进程,pid: "<<getpid()<<endl;
        sleep(1);
    }
    return 0;
}
